package com.hotel.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.hotel.common.enums.BaseResultCodeEnum;
import com.hotel.common.result.CommonResult;
import com.hotel.common.result.SingleResult;
import com.hotel.entity.ImageInfo;
import com.hotel.service.ImageInfoService;

@Controller
@RequestMapping("/image")
public class ImageInfoController {
	
	@Autowired
	private ImageInfoService imageInfoService;
	
	
	@RequestMapping(value="/upload",method=RequestMethod.POST)
	public CommonResult image(@PathVariable String type,@PathVariable Integer id , @RequestParam("file") MultipartFile file) {
		try {
			ImageInfo imageInfo = new ImageInfo();
			imageInfo.setType(type);
			imageInfo.setTypeId(id);
			String url = imageInfoService.save(imageInfo, file);
			SingleResult<String> result = new SingleResult<String>(BaseResultCodeEnum.ERR_CODE_200, url);
			return result;
		} catch (Exception e) {
			SingleResult<String> result = new SingleResult<String>(BaseResultCodeEnum.ERR_CODE_30006, e.getMessage());
			return result;
		}
		
		
		
		
	}
	

	
}
